package com.xuliugen.security.web.filter;

import javax.servlet.*;
import java.io.IOException;
import java.util.Date;

/**
 * Created by xuliugen on 2017/11/5.
 */
//@Component 如果使用Component注解就不需要进行注册，如果没有使用Component注解的话就需要使用FilterRegistrationBean机你选哪个注册
public class TimeFilter implements Filter {

    @Override
    public void destroy() {
        System.out.println("time filter destroy");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("time filter start");
        long start = new Date().getTime();
        chain.doFilter(request, response);
        System.out.println("time filter 耗时:" + (new Date().getTime() - start));
        System.out.println("time filter finish");
    }

    @Override
    public void init(FilterConfig config) throws ServletException {
        System.out.println("time filter init");
    }

}
